/******************************************************************************
*	platform/platform.h
*	 by Alex Chadwick
*
*	A light weight implementation of the USB protocol stack fit for a simple
*	driver.
*
*	platform/platform.h contains definitions pertaining to the platform that
*	the system will run on.
******************************************************************************/

#ifndef _PLATFORM_PLATFORM_H
#define _PLATFORM_PLATFORM_H

#include <configuration.h>
#include <types.h>

//------------------------------------------------------------------------------
// These functions are supplied by the chipset code (Eg. broadcom2835.c)
//
Result  PowerOnUsb (void) ;
Result  PowerOffUsb (void) ;
void  MicroDelay (u32 delay) ;


//------------------------------------------------------------------------------
// LogPrint() is NOT supplied by csud
//           and NOT required if the driver is compiled as STANDALONE
// If required, it should display (or store) the supplied progress-message
//
#ifndef NO_LOG
	void  LogPrint (char* message, u32 messageLength) ;
#endif

//------------------------------------------------------------------------------
// These functions are supplied by platform.c
//
void*  MemoryAllocate (u32 length) ;
void   MemoryDeallocate (void* address) ;
void*  MemoryReserve (u32 length, void* physicalAddress) ;
void   MemoryCopy (void* destination, void* source, u32 length) ;

#ifndef NO_LOG
	void  LogPrintF (char* format, u32 formatLength, ...) ;

#	define LOG(x)             (LogPrint(x, sizeof(x)))
#	define LOGL(x, len)       (LogPrint(x, len))
#	define LOGF(x, ...)       (LogPrintF(x, sizeof(x), __VA_ARGS__))
#	define LOGFL(x, len, ...) (LogPrintF(x, len, __VA_ARGS__))
#else
#	define LOG(x)
#	define LOGL(x, len)
#	define LOGF(x, ...)
#	define LOGFL(x, len, ...)
#endif // NO_LOG

#ifdef CONFIG_DEBUG
#	define LOG_DEBUG(x)             LOG(x)
#	define LOG_DEBUGL(x, len)       LOGL(x, len)
#	define LOG_DEBUGF(x, ...)       LOGF(x, __VA_ARGS__)
#	define LOG_DEBUGFL(x, len, ...) LOGFL(x, len, __VA_ARGS__)
#else
#	define LOG_DEBUG(x)
#	define LOG_DEBUGL(x, len)
#	define LOG_DEBUGF(x, ...)
#	define LOG_DEBUGFL(x, len, ...)
#endif // CONFIG_DEBUG

#ifdef ARM
#	ifdef ARM_V6
#		include "arm/armv6.h"
#		ifdef BROADCOM_2835
#			include "arm/broadcom2835.h"
#		endif // BROADCOM_2835
#	else
#		error Unrecognised ARM Version
#	endif // ARM_V6
#else
#	error Unrecognised Processor Family
#endif // ARM

#endif // _PLATFORM_PLATFORM_H
